/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
 */

package com.huawei.exam;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 5
 * A02 34
 * Li01 32
 * B03 34
 * C04 56
 * A05 79
 * <p>
 * B03 A02
 *
 * @author z00611952
 * @since 2021/9/17
 */
public class Main2 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));

        int num = Integer.parseInt(br.readLine().trim());
        String[][] employeeList = new String[num][2];
        for (int i = 0; i < num; i++) {
            employeeList[i] = br.readLine().split(" ");
        }
        br.close();
        Solution2 solution = new Solution2();
        List<String> result = solution.getMediumNameList(employeeList);
        if (result != null) {
            System.out.print(String.join(" ", result));
        }
    }

}

class Solution2 {
    // 待实现函数，在此函数中填入答题代码
    List<String> getMediumNameList(String[][] employeeList) {
        List<String> result = new ArrayList<>();
        int midNumber = 0;
        int count = employeeList.length;
        Map<Integer, List<String>> map = new HashMap<>();
        List<String[]> list = new ArrayList<>();

        for (String[] employee : employeeList) {
            list.add(employee);
            map.computeIfAbsent(Integer.parseInt(employee[1]), key -> new ArrayList<>()).add(employee[0]);
        }
        Collections.sort(list, Comparator.comparingInt(employee -> Integer.parseInt(employee[1])));
        if (count % 2 == 0) {
            // 偶数
            midNumber = Math.min(Integer.parseInt(list.get(count / 2)[1]),
                Integer.parseInt(list.get(count / 2 - 1)[1]));
        } else {
            // 奇数
            midNumber = Integer.parseInt(list.get(count / 2)[1]);
        }
        if (map.containsKey(midNumber)) {
            result = map.get(midNumber);
        }
        Collections.reverse(result);
        return result;
    }

}
